<%@ tag language="java" pageEncoding="UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>

<%@ attribute name="value" type="java.lang.String" required="true" description="隐藏值" %>
<%@ attribute name="label" type="java.lang.String" required="true" description="显示值" %>
<%@ attribute name="id" type="java.lang.String" required="true" description="元素ID" %>
<%@ attribute name="type" type="java.lang.String" required="true" description="checkbox或radio" %>
<%@ attribute name="url" type="java.lang.String" required="true" description="访问路径" %>

<input type="hidden" id="${id}-id" name="dictStandards.id" value="${value}">
<input type="text" id="${id}-name" name="dictStandards.name" class="form-control required"
       onclick="${id}PopupLayerTable(this)" readonly value="${label}"
       data-url="${url}?selectType=${type}">

<script type="text/javascript">
    function ${id}PopupLayerTable(thisObject){
        top.layer.open({
            type: 2
            ,title: false
            ,closeBtn: false
            ,anim: 0
            ,area: ['80%', '90%']
            ,content:$(thisObject).data("url")
            ,btn: ['确定', '取消']
            ,yes: function(index, layero){
                let layuiTable = layero.find("iframe")[0].contentWindow.layui.table;
                console.trace(layuiTable)
                let checkStatus = layuiTable.checkStatus('layui-table-id1');
                console.trace(checkStatus.data)
                let ids =[];
                let noInvalidData = true;
                $.each(checkStatus.data,function(index,obj){
                    // console.trace('obj',obj)
                    if(obj.id === undefined){
                        layer.msg('异常数据，无法执行相关操作！', {icon: 5});
                        noInvalidData = false;
                        return false;
                    }
                    ids.push(obj.id);
                });
                console.log(noInvalidData,ids.length)
                //  判断正常数据是否存在
                if(noInvalidData && ids.length < 1){
                    top.layer.msg('未选中数据！', {icon: 5});
                    return false;
                }
                $('#${id}-id').val(ids);
                $('#${id}-name').val(checkStatus.data[0].name);
                top.layer.close(index);
            }
        });
    }

</script>
